package com.study.juc2;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @author study
 * @version 1.0
 * @date 2020/9/22 22:37
 */
public class BlockingQueueDemo {
    public static void main(String[] args) {
        BlockingQueue<String> blockedQueue = new ArrayBlockingQueue<>(3);
        System.out.println(blockedQueue.add("a"));
        System.out.println(blockedQueue.add("b"));
        System.out.println(blockedQueue.add("c"));
        //System.out.println(blockedQueue.add("x"));//IllegalStateException 队列已满会抛出异常
        // System.out.println(blockedQueue.remove());
        // System.out.println(blockedQueue.remove());
        // System.out.println(blockedQueue.remove());
        // System.out.println(blockedQueue.remove());//.NoSuchElementException

        //检查队首元素
        System.out.println(blockedQueue.element());
        System.out.println(blockedQueue.offer("x"));//队列满了 返回fasle


    }
}
